#! /bin/bash
set -x 
tmp_file0=$(tempfile)
./adb shell getevent -t > $tmp_file0 &
bg_pid=$!

read
kill -9 $bg_pid
tmp_file1=$(tempfile)
cat $tmp_file0 | grep /.*: 2>&1 | awk -F':? +' '{printf "%s|%s %d %d %d\n", $1, $2, strtonum("0x"$3), strtonum("0x"$4), strtonum("0x"$5)}' | awk -F'-' '{print $1 "." $2}'> $tmp_file1

tmp_file2=$(tempfile)
cat $tmp_file1 | awk -F"|" 'BEGIN{old=0.0; val=0.0;} {if(old != 0){val=strtonum($1)-old} if(val >= 0.1){printf "sleep %f;\n", val}; printf "sendevent %s;\n",$2; old=strtonum($1)}' > $tmp_file2 

./adb push $tmp_file2 /sdcard$tmp_file2
./adb shell "sh /sdcard$tmp_file2"

rm $tmp_file0 $tmp_file1 $tmp_file2

set -
exit 0
